<?php

class Core_Backend_Component_Ebook_View_Material_Index extends Core_Backend_Share_View_Grid {

    protected function buildToolbar($toolbar) {
    	parent::buildToolbar($toolbar);
    	$group = $toolbar->createGroup();
        $group->addLink($this->getUrl(array('areaid'=>$this->getCurrentAreaId()), 'create'), $this->__('share.button.create'));
    }

    protected function buildGrid($grid) {
    	$grid->setId('material_grid')
                ->setPrimaryKey('id');
//                ->setAllowFilter(TRUE)
//                ->setSortField($this->getRequest()->getParameter('sort', 'id'))
//                ->setSortDirection($this->getRequest()->getParameter('dir', 'asc'));
        $grid->addLabelColumn($this->__('share.label.title'), 'title', '{title}')->setWidth(200);
        $grid->addLabelColumn($this->__('share.label.road'), 'road_ids', '{road_id}');
        $grid->addLabelColumn($this->__('share.label.industry'), 'industry_ids', '{industry_id}');
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        if($this->getIdentity()->isAllowAction('ebook_material_generate')){         
	        $grid->addLinkColumn('#', 'generate', $this->getUrl(array('id' => '{id}'), 'generate'), $this->__('share.button.generate'))
	                ->setWidth(40)
	                ->setAlign('center')
	                ->getCell()->setTarget('_blank');
        }
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        $pagination->setUrlFormat($this->getPaginationUrl())->setRecordCount($this->getRecords());
        parent::buildPagination($pagination);
    }

}